package com.bang.itstack.day06.adapter;

import com.alibaba.fastjson.JSONObject;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import java.util.Set;

/**
 * @ClassName: MQAdapter
 * @Desc: TODO
 * @author: <Bang>
 * @Date: 2021/10/21 19:44
 * @Version: 1.0
 * @Modified By:
 */
public class MQAdapter {

    public static RebateInfo filter(String jsonStr, Map<String, String> link) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
        return filter(JSONObject.parseObject(jsonStr, Map.class), link);
    }

    public static RebateInfo filter(Map map, Map<String, String> link) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        RebateInfo rebateInfo = new RebateInfo();
        Set<String> keySet = link.keySet();
        for (String key : keySet) {
            Object val = map.get(link.get(key));
            if (null!=val){
                RebateInfo.class.getMethod("set" + key.substring(0, 1).toUpperCase() + key.substring(1), String.class).invoke(rebateInfo, val.toString());
            }
        }
        return rebateInfo;
    }
}
